package 二叉树;

import static java.lang.Math.min;

public class LC_530二叉搜索树最小绝对差 {
    public class TreeNode {
        int val;
        LC_530二叉搜索树最小绝对差.TreeNode left;
        LC_530二叉搜索树最小绝对差.TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, LC_530二叉搜索树最小绝对差.TreeNode left, LC_530二叉搜索树最小绝对差.TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    int result=Integer.MAX_VALUE;
    TreeNode pre=null;
    public int getMinimumDifference(TreeNode root) {
        if(root==null) return 0;
        getMinimumDifference(root.left);
        if(pre!=null)
            result=min(result,root.val-pre.val);
        pre=root;
        getMinimumDifference(root.right);
        return result;
    }
}
